package com.xiaoshuidi.cloud.module.iot.api.device;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.xiaoshuidi.cloud.module.iot.api.device.vo.*;
import com.xiaoshuidi.cloud.module.iot.common.ResultModel;
import com.xiaoshuidi.cloud.module.iot.controller.admin.doorlock.vo.PullDeviceVo;
import com.xiaoshuidi.cloud.module.iot.dal.mapper.DeviceDoMapper;
import com.xiaoshuidi.cloud.module.iot.dal.model.ammeter.AmmeterInfoReqModel;
import com.xiaoshuidi.cloud.module.iot.dal.model.ammeter.AmmeterReportResVO;
import com.xiaoshuidi.cloud.module.iot.dal.model.ammeter.AmmeterSwitchOnOffReqVO;
import com.xiaoshuidi.cloud.module.iot.dal.model.doorLock.AddPasswordModel;
import com.xiaoshuidi.cloud.module.iot.dal.model.doorLock.DoorLockInfo;
import com.xiaoshuidi.cloud.module.iot.dal.model.watermeter.WaterMeterCommonRequestModel;
import com.xiaoshuidi.cloud.module.iot.dal.model.watermeter.WaterMeterSwitchOnOffReqVO;
import com.xiaoshuidi.cloud.module.iot.dal.model.watermeter.details.WaterMeterReportRequestModel;
import com.xiaoshuidi.cloud.module.iot.dal.model.watermeter.details.WaterMeterReportResponseModel;
import com.xiaoshuidi.cloud.module.iot.dal.pojo.DevicePrice;
import com.xiaoshuidi.cloud.module.iot.dal.pojo.TbDeviceDo;
import com.xiaoshuidi.cloud.module.iot.dal.pojo.TbDeviceDosageDo;
import com.xiaoshuidi.cloud.module.iot.dal.pojo.TbDoorlockPassword;
import com.xiaoshuidi.cloud.module.iot.dal.repository.DeviceDosageRepository;
import com.xiaoshuidi.cloud.module.iot.dal.repository.TbDoorLockPasswordRepository;
import com.xiaoshuidi.cloud.module.iot.enums.ErrorCodeEnum;
import com.xiaoshuidi.cloud.module.iot.enums.RedisTypeEnum;
import com.xiaoshuidi.cloud.module.iot.service.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;


/**
 * @Author Feng
 * @date 2023/6/19
 */
@Slf4j
@RestController
@Validated
@RequiredArgsConstructor
public class DeviceApiImpl implements DeviceApi {


    @Autowired
    private LocalDeviceService localDeviceService;
    @Autowired
    private DoorLockService doorLockService;
    @Autowired
    private AmmeterService ammeterService;
    @Autowired
    private WaterMeterService waterMeterService;
    @Autowired
    private DeviceDosageRepository deviceDosageDataAccess;
    @Autowired
    private TbDoorLockPasswordRepository doorLockPasswordDataAccess;
    @Autowired
    private InteceptorService inteceptorService;
    @Autowired
    private CacheService cacheService;
    @Autowired
    DeviceDosageRepository deviceDosageRepository;
    @Autowired
    private DeviceDoMapper deviceDoMapper;


    @Override
    public ResultModel<PageInfo<PullDeviceApiVo>> findDeviceListByDeviceNosPage(DeviceListByNosApiReqVO deviceListByNosReqVO) {
        ResultModel<PageInfo<PullDeviceApiVo>> resultModel = null;
        try {
            resultModel = localDeviceService.findDeviceListByDeviceNosPage(deviceListByNosReqVO);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel = ResultModel.createNativeFail(ErrorCodeEnum.SYSTEM_EXCEPTION.getMsg());
        }
        return resultModel;
    }

    @Override
    public ResultModel<List<PullDeviceApiVo>> findDeviceList(DeviceListByNosApiReqVO deviceListByNosReqVO) {
        ResultModel<List<PullDeviceApiVo>> resultModel = null;
        try {
            resultModel = localDeviceService.findDeviceList(deviceListByNosReqVO);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel = ResultModel.createNativeFail(ErrorCodeEnum.SYSTEM_EXCEPTION.getMsg());
        }
        return resultModel;
    }

    @Override
    public ResultModel<AddPasswordModelVo> deletePassword(AddPasswordModelVo addPasswordModel) {
        ResultModel<AddPasswordModelVo> resultModel = null;
        try {
            resultModel = doorLockService.deletePassword(addPasswordModel);
        } catch (Exception e) {
            resultModel = ResultModel.createNativeFail("删除密码失败");
        }
        return resultModel;
    }

    @Override
    public ResultModel<AmmeterInfoRes> getAmmeterInfo(AmmeterInfoReq ammeterInfoReq) {
        ResultModel<AmmeterInfoRes> resultModel = null;
        try {
            AmmeterInfoReqModel model = new AmmeterInfoReqModel();
            BeanUtil.copyProperties(ammeterInfoReq, model);
            ResultModel<AmmeterInfoResModel> ammeterInfo = ammeterService.getAmmeterInfo(model);
            AmmeterInfoResModel data = ammeterInfo.getData();
            AmmeterInfoRes res = new AmmeterInfoRes();
            BeanUtil.copyProperties(data, res);
            ResultModel<AmmeterInfoRes> resultModelNew = new ResultModel<>();
            resultModelNew.setData(res);
            resultModel = resultModelNew;
        } catch (Exception e) {
            e.printStackTrace();
            resultModel = ResultModel.createNativeFail(e.getMessage());
        }
        return resultModel;
    }

    @Override
    public ResultModel<AmmeterReportRes> getAmmeterReport(WaterMeterReportRequest ammeterReportReq) {
        ResultModel<AmmeterReportRes> resultModel = null;
        try {
            WaterMeterReportRequestModel model = new WaterMeterReportRequestModel();
            BeanUtil.copyProperties(ammeterReportReq, model);
            ResultModel<AmmeterReportResVO> ammeterReport = ammeterService.getAmmeterReport(model);
            AmmeterReportResVO data = ammeterReport.getData();
            AmmeterReportRes res = new AmmeterReportRes();
            BeanUtil.copyProperties(data, res);
            ResultModel<AmmeterReportRes> resultModelNew = new ResultModel<>();
            resultModelNew.setData(res);
            resultModel = resultModelNew;
        } catch (Exception e) {
            e.printStackTrace();
            resultModel = ResultModel.createNativeFail(e.getMessage());
        }
        return resultModel;
    }

    @Override
    public ResultModel<WaterMeterCommonResponse> getWatermeterInfo(WaterMeterCommonRequest waterMeterCommonRequest) {
        ResultModel<WaterMeterCommonResponse> resultModel = null;
        try {
            WaterMeterCommonRequestModel model = new WaterMeterCommonRequestModel();
            BeanUtil.copyProperties(waterMeterCommonRequest, model);
            ResultModel<WaterMeterCommonResponseModel> watermeterInfo = this.waterMeterService.getWatermeterInfo(model);
            WaterMeterCommonResponseModel data = watermeterInfo.getData();
            WaterMeterCommonResponse response = new WaterMeterCommonResponse();
            BeanUtil.copyProperties(data, response);
            ResultModel<WaterMeterCommonResponse> resultModelNew = new ResultModel<>();
            resultModelNew.setData(response);
            resultModel = resultModelNew;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return resultModel;
    }

    @Override
    public ResultModel<WaterMeterReportResponse> getWatermeterReport(WaterMeterReportRequest waterMeterReportRequest) {
        ResultModel<WaterMeterReportResponse> resultModel = null;
        try {
            WaterMeterReportRequestModel model = new WaterMeterReportRequestModel();
            BeanUtil.copyProperties(waterMeterReportRequest, model);
            ResultModel<WaterMeterReportResponseModel> watermeterReport = this.waterMeterService.getWatermeterReport(model);
            WaterMeterReportResponseModel data = watermeterReport.getData();
            WaterMeterReportResponse response = new WaterMeterReportResponse();
            BeanUtil.copyProperties(data, response);
            ResultModel<WaterMeterReportResponse> resultModelNew = new ResultModel<>();
            resultModelNew.setData(response);
            resultModel = resultModelNew;
        } catch (Exception e) {
            e.printStackTrace();
            resultModel = ResultModel.createNativeFail(e.getMessage());
        }
        return resultModel;
    }

    @Override
    public ResultModel<List<AddPassword>> getPasswordList(String deviceNo, String mobile) {
        ResultModel<List<AddPasswordModel>> passwordList = doorLockService.getPasswordList(deviceNo, mobile);
        List<AddPasswordModel> data = passwordList.getData();
        List<AddPassword> list = new ArrayList<>();
        for (AddPasswordModel model : data) {
            AddPassword password = new AddPassword();
            BeanUtil.copyProperties(model, password);
            password.setPasswordType(model.getPasswordType());
            list.add(password);
        }
        ResultModel<List<AddPassword>> resultModel = new ResultModel<>();
        resultModel.setData(list);
        return resultModel;
    }

    @Override
    public ResultModel<AddPassword> updatePassword(AddPassword addPassword) {
        ResultModel<AddPassword> resultModel = null;
        try {
            AddPasswordModel model = new AddPasswordModel();
            BeanUtil.copyProperties(addPassword, model);
            model.setPasswordType(addPassword.getPasswordType());
            ResultModel<AddPasswordModel> addPasswordModelResultModel = doorLockService.updatePassword(model);
            AddPasswordModel data = addPasswordModelResultModel.getData();
            AddPassword password = new AddPassword();
            BeanUtil.copyProperties(data, password);
            ResultModel<AddPassword> resultModelNew = new ResultModel<>();
            resultModelNew.setData(password);
            resultModel = resultModelNew;
        } catch (Exception e) {
            resultModel = ResultModel.createNativeFail("修改密码失败");
        }
        return resultModel;
    }

    @Override
    public ResultModel<DoorLockInformation> getDoorlockInfo(String deviceNo) {
        ResultModel<DoorLockInfo> doorlockInfo = doorLockService.getDoorlockInfo(deviceNo);
        DoorLockInfo data = doorlockInfo.getData();
        DoorLockInformation doorLockInformation = new DoorLockInformation();
        BeanUtil.copyProperties(data, doorLockInformation);
        ResultModel<DoorLockInformation> resultModel = new ResultModel<>();
        resultModel.setData(doorLockInformation);
        return resultModel;
    }

    @Override
    public ResultModel<DevicePriceVo> getCurrentReading(String deviceNo, String deviceType) {
        DevicePrice devicePrice = localDeviceService.getCurrentReading(deviceNo);
        DevicePriceVo devicePriceVo = null;
        if (null != devicePrice) {
            devicePriceVo = new DevicePriceVo();
            devicePriceVo.setDeviceNo(devicePrice.getDeviceNo());
            devicePriceVo.setDeviceThireNo(devicePrice.getDeviceThireNo());
            devicePriceVo.setId(devicePrice.getId());
            devicePriceVo.setYear(devicePrice.getYear());
            devicePriceVo.setReadAccount(devicePrice.getReadAccount());
            TbDeviceDosageDo deviceDosageDo = deviceDosageDataAccess.getTbDeviceDosageDo(deviceNo);
            devicePriceVo.setRead(deviceDosageDo.getEndAmount());
            devicePriceVo.setDeviceType(deviceType);
            devicePriceVo.setAmount(deviceDosageDo.getAmount());
            devicePriceVo.setSageTime(deviceDosageDo.getDosageDate());
        }
        return ResultModel.createSuccess(devicePriceVo);
    }

    @Override
    public ResultModel<WaterMeterCommonResponseModel> refreshWatermeterInfo(String deviceNo, Long roomId) {
        ResultModel<WaterMeterCommonResponseModel> waterMeterCommonResponseModelResultModel = null;
        try {
            WaterMeterCommonRequestModel waterMeterCommonRequestModel = new WaterMeterCommonRequestModel();
            waterMeterCommonRequestModel.setRoomId(roomId);
            waterMeterCommonRequestModel.setDeviceNo(deviceNo);
            waterMeterCommonResponseModelResultModel = waterMeterService.refreshWatermeterInfo(waterMeterCommonRequestModel);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return waterMeterCommonResponseModelResultModel;
    }

    @Override
    public ResultModel<WaterMeterCommonResponseModel> refreshWatermeterInfo1(String deviceNo, Long roomId, boolean charging) {
        ResultModel<WaterMeterCommonResponseModel> waterMeterCommonResponseModelResultModel = null;
        try {
            WaterMeterCommonRequestModel waterMeterCommonRequestModel = new WaterMeterCommonRequestModel();
            waterMeterCommonRequestModel.setRoomId(roomId);
            waterMeterCommonRequestModel.setDeviceNo(deviceNo);
            waterMeterCommonRequestModel.setCharging(charging);
            waterMeterCommonResponseModelResultModel = waterMeterService.refreshWatermeterInfo(waterMeterCommonRequestModel);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return waterMeterCommonResponseModelResultModel;
    }

    @Override
    public ResultModel<AmmeterInfoResModel> refreshAmmeterInfo(String deviceNo, Long roomId) {
        ResultModel<AmmeterInfoResModel> resModelResultModel = null;
        AmmeterInfoReqModel ammeterInfoReqModel = new AmmeterInfoReqModel();
        ammeterInfoReqModel.setDeviceNo(deviceNo);
        ammeterInfoReqModel.setRoomId(roomId);
        try {
            resModelResultModel = ammeterService.refreshAmmeterInfo(ammeterInfoReqModel);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return resModelResultModel;
    }

    @Override
    public ResultModel<AmmeterInfoResModel> refreshAmmeterInfo1(String deviceNo, Long roomId, boolean charging) {
        ResultModel<AmmeterInfoResModel> resModelResultModel = null;
        AmmeterInfoReqModel ammeterInfoReqModel = new AmmeterInfoReqModel();
        ammeterInfoReqModel.setDeviceNo(deviceNo);
        ammeterInfoReqModel.setRoomId(roomId);
        ammeterInfoReqModel.setCharging(charging);
        try {
            resModelResultModel = ammeterService.refreshAmmeterInfo(ammeterInfoReqModel);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return resModelResultModel;
    }

    @Override
    public ResultModel<DeviceDosageVo> getDeviceDasage(String deviceNo) {
        TbDeviceDosageDo tbDeviceDosageDo = deviceDosageDataAccess.getTbDeviceDosageDo(deviceNo);
        DeviceDosageVo deviceDosageVo = new DeviceDosageVo();
        deviceDosageVo.setDosageDate(tbDeviceDosageDo.getDosageDate());
        deviceDosageVo.setStartDosageDate(tbDeviceDosageDo.getStartDosageDate());
        deviceDosageVo.setStatus(tbDeviceDosageDo.getStatus());
        deviceDosageVo.setEndAmount(tbDeviceDosageDo.getEndAmount());
        deviceDosageVo.setTotalAmount(tbDeviceDosageDo.getTotalAmount());
        deviceDosageVo.setStartAmount(tbDeviceDosageDo.getStartAmount());
        deviceDosageVo.setAmount(tbDeviceDosageDo.getAmount());
        deviceDosageVo.setDeviceNo(tbDeviceDosageDo.getDeviceNo());
        return ResultModel.createSuccess(deviceDosageVo);
    }

    @Override
    public ResultModel updateSage(DeviceDosageVo deviceDosageVo) {
        ammeterService.updateSage(deviceDosageVo);
        return ResultModel.createSuccess();
    }

    @Override
    public ResultModel unbind(String deviceNo) {
        //门锁解绑先删除门锁所有密码
        try {
            List<TbDoorlockPassword> passwords = doorLockPasswordDataAccess.findByDeviceAndCreateUser(deviceNo, null);
            for (TbDoorlockPassword tbDoorlockPassword : passwords) {
                AddPasswordModelVo addPasswordModelVo = new AddPasswordModelVo();
                addPasswordModelVo.setDeviceNo(tbDoorlockPassword.getDeviceNo());
                addPasswordModelVo.setThirdPassId(tbDoorlockPassword.getThirdPasswordId());
                addPasswordModelVo.setPasswordType(tbDoorlockPassword.getPasswordType());
                doorLockService.deletePassword(addPasswordModelVo);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultModel.createSuccess();
    }

    @Override
    public ResultModel<AddPassword> addPassword(AddPassword addPasswordModel) {
        log.info("gataway->doorlock,下发密码请求参数,AddPasswordModel:{}", JSONObject.toJSONString(addPasswordModel));
        ResultModel<AddPassword> resultModel = null;
        try {
            AddPasswordModel passwordModel = new AddPasswordModel();
            //下发门锁密码防重
            String key = new StringBuilder().append(RedisTypeEnum.SDIOT_REFRESHDOORLOCK.getCode()).append(addPasswordModel.getDeviceNo()).toString();
            if (cacheService.setIfAbsent(key, addPasswordModel.getDeviceNo())) {
                cacheService.expire(key, 60);
                passwordModel.setPassword(addPasswordModel.getPassword());
                passwordModel.setStartTime(addPasswordModel.getStartTime());
                passwordModel.setEndTime(addPasswordModel.getEndTime());
                passwordModel.setMobile(addPasswordModel.getMobile());
                passwordModel.setDeviceNo(addPasswordModel.getDeviceNo());
                passwordModel.setUserName(addPasswordModel.getUserName());
                passwordModel.setOperatorName(addPasswordModel.getOperatorName());
                passwordModel.setUserType("租客");
                passwordModel.setGate(addPasswordModel.getGate());
                passwordModel.setPasswordType(addPasswordModel.getPasswordType());
                ResultModel<AddPasswordModel> addPasswordModelResultModel = doorLockService.addPassword(passwordModel);
                cacheService.deleteObjectByKey(key);
                AddPasswordModel data = addPasswordModelResultModel.getData();
                //添加操作记录
                inteceptorService.addOperateRecord(addPasswordModel.getDeviceNo(), 2);
                AddPassword password = new AddPassword();
                BeanUtil.copyProperties(data, password);
                ResultModel<AddPassword> resultModelNew = new ResultModel<>();
                resultModelNew.setData(password);
                resultModel = resultModelNew;
            } else {
                resultModel = ResultModel.createNativeFail("请勿重复下发密码");
            }

        } catch (Exception e) {
            e.printStackTrace();
            log.error("doorlock->下发密码请求,请求参数：{}，异常原因：{}", JSONObject.toJSONString(addPasswordModel), e);
            resultModel = ResultModel.createNativeFail(e.getMessage());
        }
        return resultModel;
    }

    @Override
    public ResultModel<List<DeviceWaringVo>> getDeviceWaring(List<DeviceWaringVo> deviceWaringVo) {
        List<DeviceWaringVo> waringVoList = new ArrayList<>();
        for (DeviceWaringVo deviceNo : deviceWaringVo) {
            Double oneDayRead = deviceDosageRepository.getOneDayRead(deviceNo.getDeviceNo());
            if (oneDayRead.compareTo(deviceNo.getRead()) < 0) {
                DeviceWaringVo deviceWaring = new DeviceWaringVo();
                deviceWaring.setDeviceNo(deviceNo.getDeviceNo());
                deviceWaring.setRead(oneDayRead);
                waringVoList.add(deviceWaring);
            }
        }
        return ResultModel.createSuccess(waringVoList);
    }

    @Override
    public ResultModel deletePassWordByMobile(String deviceNo, String mobile) {
        List<TbDoorlockPassword> passWordByMobile = doorLockPasswordDataAccess.getPassWordByMobile(deviceNo, mobile);
        try {
            for (TbDoorlockPassword tbDoorlockPassword : passWordByMobile) {
                AddPasswordModelVo addPasswordModelVo = new AddPasswordModelVo();
                addPasswordModelVo.setDeviceNo(tbDoorlockPassword.getDeviceNo());
                addPasswordModelVo.setThirdPassId(tbDoorlockPassword.getThirdPasswordId());
                addPasswordModelVo.setPasswordType(tbDoorlockPassword.getPasswordType());
                doorLockService.deletePassword(addPasswordModelVo);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultModel.createSuccess();
    }

    @Override
    public ResultModel unFrozenPassword(String deviceNo, String mobile) {
        //冻结密码
        TbDoorlockPassword tbDoorlockPassword = new TbDoorlockPassword();
        tbDoorlockPassword.setDeviceNo(deviceNo);
        tbDoorlockPassword.setMemberMobile(mobile);
        tbDoorlockPassword.setStatus(1);
        TbDoorlockPassword doorlockPassword = doorLockPasswordDataAccess.selectTbDoorlockPassword(tbDoorlockPassword);
        AddPasswordModel addPasswordModel = new AddPasswordModel();
        addPasswordModel.setDeviceNo(deviceNo);
        addPasswordModel.setThirdPassId(doorlockPassword.getThirdPasswordId());
        try {
            doorLockService.unfrozenPassword(addPasswordModel);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public ResultModel setWaterMeterSwitchOn(String deviceNo) {
        WaterMeterSwitchOnOffReqVO waterMeterSwitchOnOffReqVO = new WaterMeterSwitchOnOffReqVO();
        TbDeviceDo tbDeviceDo = new TbDeviceDo();
        waterMeterSwitchOnOffReqVO.setTbDeviceDo(tbDeviceDo);
        waterMeterSwitchOnOffReqVO.setDeviceNo(deviceNo);
        try {
            waterMeterService.setWaterMeterSwitchOn(waterMeterSwitchOnOffReqVO);
        } catch (Exception e) {
            e.printStackTrace();
            log.info("waterMeter->设置水表关阀停水,请求参数：{}"+JSONObject.toJSONString(waterMeterSwitchOnOffReqVO));
        }
        return ResultModel.createSuccess();
    }

    @Override
    public ResultModel setWaterMeterSwitchOff(String deviceNo) {
        WaterMeterSwitchOnOffReqVO waterMeterSwitchOnOffReqVO = new WaterMeterSwitchOnOffReqVO();
        TbDeviceDo tbDeviceDo = new TbDeviceDo();
        waterMeterSwitchOnOffReqVO.setTbDeviceDo(tbDeviceDo);
        waterMeterSwitchOnOffReqVO.setDeviceNo(deviceNo);
        try {
            waterMeterService.setWaterMeterSwitchOff(waterMeterSwitchOnOffReqVO);
        } catch (Exception e) {
            e.printStackTrace();
            log.info("waterMeter->设置水表关阀停水,请求参数：{}"+JSONObject.toJSONString(waterMeterSwitchOnOffReqVO));
        }
        return ResultModel.createSuccess();

    }

    @Override
    public ResultModel setAmmeterSwitchOn(String deviceNo) {
        AmmeterSwitchOnOffReqVO ammeterSwitchOnOffReqVO = new AmmeterSwitchOnOffReqVO();
        TbDeviceDo tbDeviceDo = new TbDeviceDo();
        ammeterSwitchOnOffReqVO.setDeviceNo(deviceNo);
        ammeterSwitchOnOffReqVO.setTbDeviceDo(tbDeviceDo);
        try {
            ammeterService.setAmmeterSwitchOn(ammeterSwitchOnOffReqVO);
        } catch (Exception e) {
            e.printStackTrace();
            log.info("ammeter->设置电表停电,请求参数：{}"+JSONObject.toJSONString(ammeterSwitchOnOffReqVO));
        }
        return ResultModel.createSuccess();
    }

    @Override
    public ResultModel setAmmeterSwitchOff(String deviceNo) {
        AmmeterSwitchOnOffReqVO ammeterSwitchOnOffReqVO = new AmmeterSwitchOnOffReqVO();
        TbDeviceDo tbDeviceDo = new TbDeviceDo();
        ammeterSwitchOnOffReqVO.setDeviceNo(deviceNo);
        ammeterSwitchOnOffReqVO.setTbDeviceDo(tbDeviceDo);
        try {
            ammeterService.setAmmeterSwitchOff(ammeterSwitchOnOffReqVO);
        } catch (Exception e) {
            e.printStackTrace();
            log.info("ammeter->设置电表供电,请求参数：{}"+JSONObject.toJSONString(ammeterSwitchOnOffReqVO));
        }
        return ResultModel.createSuccess();
    }

    /**
     * 查询门锁状态
     * @param time
     * @return
     */
    public ResultModel<List<PullDeviceApiVo>> queryDeviceState(String deviceType, String time){
        List<PullDeviceVo> pullDeviceVos = deviceDoMapper.queryDeviceState(deviceType, time);
        List<PullDeviceApiVo> pullDeviceApiVos = BeanUtil.copyToList(pullDeviceVos, PullDeviceApiVo.class);
        return ResultModel.createSuccess(pullDeviceApiVos);
    }

    /**
     * 连续未开门
     * @param time
     * @return
     */
    public ResultModel<List<PullDeviceApiVo>> queryNotOpenDoor(String time){
        List<PullDeviceVo> pullDeviceVos = deviceDoMapper.queryNotOpenDoor(time);
        List<PullDeviceApiVo> pullDeviceApiVos = BeanUtil.copyToList(pullDeviceVos, PullDeviceApiVo.class);
        return ResultModel.createSuccess(pullDeviceApiVos);
    }

    /**
     * 未出租连续开门
     * @param time
     * @return
     */
    public ResultModel<List<PullDeviceApiVo>> queryOpenDoor(String time){
        List<PullDeviceVo> pullDeviceVos = deviceDoMapper.queryOpenDoor(time);
        List<PullDeviceApiVo> pullDeviceApiVos = BeanUtil.copyToList(pullDeviceVos, PullDeviceApiVo.class);
        return ResultModel.createSuccess(pullDeviceApiVos);
    }

    /**
     * 连续开门记录
     * @param time
     * @return
     */
    public ResultModel<List<PullDeviceApiVo>> queryOpenNum(String time){
        List<PullDeviceVo> pullDeviceVos = deviceDoMapper.queryOpenNum(time);
        List<PullDeviceApiVo> pullDeviceApiVos = BeanUtil.copyToList(pullDeviceVos, PullDeviceApiVo.class);
        return ResultModel.createSuccess(pullDeviceApiVos);
    }


}



